/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.webapp.alliance;

import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.AlliancesManager;
import cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl.AlliancesManagerImpl;
import cz.muni.fi.diplomka.webapp.layout.EmptyPanel;
import cz.muni.fi.diplomka.webapp.layout.LinkPanel;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

/**
 *
 * @author Jakub Kutil
 */
public class AlliancePage extends WebPage {

    private AlliancesManager alliancesManager = new AlliancesManagerImpl();

    public AlliancePage(PageParameters parameters) {
        final Long id;

        add(new FeedbackPanel("feedback"));

        if (parameters.containsKey("id")) {
            id = Long.parseLong(parameters.getString("id"));
            
            PageParameters p = new PageParameters();
            p.add("id", parameters.getString("id"));
            
            add(new LinkPanel("linkPanel", p));
            
            if (alliancesManager.getAllianceOfPlayer(id).getId() == null) {
                add(new EmptyPanel("allianceMemberPanel"));
                add(new CreatePanel("createPanel", p));
                if (alliancesManager.getAllAlliances().isEmpty()) {
                    add(new EmptyPanel("joinPanel"));
                } else {
                    add(new JoinPanel("joinPanel", p));
                }
            } else {
                add(new EmptyPanel("joinPanel"));
                add(new EmptyPanel("createPanel"));
                add(new AllianceMemberPanel("allianceMemberPanel", p));
            }
        }
    }
}
